/***********************************************************************************
 @file   
 @author
 @attention
 ***********************************************************************************/
#include "mid_lcd.h"
/***********************************************************************************
 * @global
***********************************************************************************/
_lcd_obj lcd_obj;
/***********************************************************************************
 * @local  
***********************************************************************************/
const uint32_t dis_table_1[] = {	
((CHAR_0 & 0xf0) <<4 | (CHAR_0 & 0x0f)),  //0 
((CHAR_1 & 0xf0) <<4 | (CHAR_1 & 0x0f)),  //1 
((CHAR_2 & 0xf0) <<4 | (CHAR_2 & 0x0f)),  //2
((CHAR_3 & 0xf0) <<4 | (CHAR_3 & 0x0f)),  //3 
((CHAR_4 & 0xf0) <<4 | (CHAR_4 & 0x0f)),  //4 
((CHAR_5 & 0xf0) <<4 | (CHAR_5 & 0x0f)),  //5 
((CHAR_6 & 0xf0) <<4 | (CHAR_6 & 0x0f)),  //6 
((CHAR_7 & 0xf0) <<4 | (CHAR_7 & 0x0f)),  //7 
((CHAR_8 & 0xf0) <<4 | (CHAR_8 & 0x0f)),  //8 
((CHAR_9 & 0xf0) <<4 | (CHAR_9 & 0x0f)),  //9 

((CHAR_A & 0xf0) <<4 | (CHAR_A & 0x0f)),  //A 
((CHAR_b & 0xf0) <<4 | (CHAR_b & 0x0f)),  //b 
((CHAR_C & 0xf0) <<4 | (CHAR_C & 0x0f)),  //C 
((CHAR_d & 0xf0) <<4 | (CHAR_d & 0x0f)),  //d 
((CHAR_E & 0xf0) <<4 | (CHAR_E & 0x0f)),  //E 
((CHAR_F & 0xf0) <<4 | (CHAR_F & 0x0f)),  //F 
((CHAR_S & 0xf0) <<4 | (CHAR_S & 0x0f)),  //S 
((CHAR_U & 0xf0) <<4 | (CHAR_U & 0x0f)),  //U
((CHAR_L & 0xf0) <<4 | (CHAR_L & 0x0f)),  //L
((CHAR_G & 0xf0) <<4 | (CHAR_G & 0x0f)),  //G
((CHAR_O & 0xf0) <<4 | (CHAR_O & 0x0f)),  //O
((CHAR_N & 0xf0) <<4 | (CHAR_N & 0x0f)),  //N
};

const uint32_t dis_table_2[] = {
((CHAR_0 & 0xf0) <<4<<16 | (CHAR_0 & 0x0f)<<16),  //0 
((CHAR_1 & 0xf0) <<4<<16 | (CHAR_1 & 0x0f)<<16),  //1 
((CHAR_2 & 0xf0) <<4<<16 | (CHAR_2 & 0x0f)<<16),  //2
((CHAR_3 & 0xf0) <<4<<16 | (CHAR_3 & 0x0f)<<16),  //3 
((CHAR_4 & 0xf0) <<4<<16 | (CHAR_4 & 0x0f)<<16),  //4 
((CHAR_5 & 0xf0) <<4<<16 | (CHAR_5 & 0x0f)<<16),  //5 
((CHAR_6 & 0xf0) <<4<<16 | (CHAR_6 & 0x0f)<<16),  //6 
((CHAR_7 & 0xf0) <<4<<16 | (CHAR_7 & 0x0f)<<16),  //7 
((CHAR_8 & 0xf0) <<4<<16 | (CHAR_8 & 0x0f)<<16),  //8 
((CHAR_9 & 0xf0) <<4<<16 | (CHAR_9 & 0x0f)<<16),  //9 
((CHAR_A & 0xf0) <<4<<16 | (CHAR_A & 0x0f)<<16),  //A 
((CHAR_b & 0xf0) <<4<<16 | (CHAR_b & 0x0f)<<16),  //b 
((CHAR_C & 0xf0) <<4<<16 | (CHAR_C & 0x0f)<<16),  //C 
((CHAR_d & 0xf0) <<4<<16 | (CHAR_d & 0x0f)<<16),  //d 
((CHAR_E & 0xf0) <<4<<16 | (CHAR_E & 0x0f)<<16),  //E 
((CHAR_F & 0xf0) <<4<<16 | (CHAR_F & 0x0f)<<16),  //F 
((CHAR_S & 0xf0) <<4<<16 | (CHAR_S & 0x0f)<<16),  //S 
((CHAR_U & 0xf0) <<4<<16 | (CHAR_U & 0x0f)<<16),  //U 
((CHAR_L & 0xf0) <<4<<16 | (CHAR_L & 0x0f)<<16),  //L 
((CHAR_G & 0xf0) <<4<<16 | (CHAR_G & 0x0f)<<16),  //G 
((CHAR_O & 0xf0) <<4<<16 | (CHAR_O & 0x0f)<<16),  //O 
((CHAR_N & 0xf0) <<4<<16 | (CHAR_N & 0x0f)<<16),  //N
}; 

const uint32_t dis_table_3[] = {
ADDR1_CHAR0,  //0 
ADDR1_CHAR1,  //1 
ADDR1_CHAR2,  //2
ADDR1_CHAR3,  //3 
ADDR1_CHAR4,  //4 
ADDR1_CHAR5,  //5 
ADDR1_CHAR6,  //6 
ADDR1_CHAR7,  //7 
ADDR1_CHAR8,  //8 
ADDR1_CHAR9,  //9 
};
/***********************************************************************************
 * @brief  配置LCD寄存器
 * @param  供电选择
***********************************************************************************/
void lcd_reg_init(uint8_t pw)
{
    //SEG0~SEG6 + SEG17~SEG27 输出使能0，关闭1
    stc_lcd_cfg_t LcdInitStruct;
    stc_lcd_segcom_t LcdSegCom;         
    #if(defined(HARD_WARE)&&(HARD_WARE==HARD_WARE_FIRST))
    LcdSegCom.u32Seg0_31 = 0xC001FF80;  
    #else
    LcdSegCom.u32Seg0_31 = 0xF001FF80;                              ///< 配置LCD_POEN0寄存器 0: SEG 输出使能 到seg27
    #endif           
    
    LcdSegCom.stc_seg32_51_com0_8_t.seg32_51_com0_8 = 0xffffffff;   ///< 初始化LCD_POEN1寄存器 全部关闭输出端口
    LcdSegCom.stc_seg32_51_com0_8_t.segcom_bit.Com0_3 = 0;          ///< 使能COM0~COM3
    LcdSegCom.stc_seg32_51_com0_8_t.segcom_bit.Mux = 0;             ///< Mux=0,Seg32_35=0,BSEL=1表示:选择外部电容工作模式，内部电阻断路
    LcdSegCom.stc_seg32_51_com0_8_t.segcom_bit.Seg32_35 = 0xf;      //32-35输出关闭
    Lcd_SetSegCom(&LcdSegCom);                                      ///< LCD COMSEG端口配置

    LcdInitStruct.LcdBiasSrc = LcdInResHighPower;                   ///< 内部电阻   LcdInResLowPower
    LcdInitStruct.LcdDuty = LcdDuty4;                               ///< 1/4 duty
    
    if(pw==1)//3.3V
        LcdInitStruct.LcdBias = LcdBias2; //LcdBias3   LcdBias2                           ///< 1/3 BIAS
    else
        LcdInitStruct.LcdBias = LcdBias3;
    
    LcdInitStruct.LcdCpClk = LcdClk2k;                              ///< 电压泵时钟频率
    LcdInitStruct.LcdScanClk = LcdClk512hz;                         ///< LCD扫描频率
    LcdInitStruct.LcdMode = LcdMode0;                               ///< 选择模式
    LcdInitStruct.LcdClkSrc = LcdRCL;                               ///< LCD时钟选择RCL
    LcdInitStruct.LcdEn   = LcdEnable;                              ///< 使能LCD模块
    Lcd_Init(&LcdInitStruct);
}
/***********************************************************************************
 * @brief     初始化外部GPIO引脚
 * @attention 引脚初始位:1111 0000 0000 0001 1111 1111 1000 0000
              LCD_POEN0：C001 FF80 0xc001ff80
***********************************************************************************/
void lcd_port_init(void)
{
    //引脚功能                    实际引脚  未标明代表引脚号相同
    Gpio_SetAnalogMode(GpioPortA, GpioPin0);  //SEG23       SEG13
    Gpio_SetAnalogMode(GpioPortA, GpioPin1);  //SEG22       SEG12
    Gpio_SetAnalogMode(GpioPortA, GpioPin2);  //SEG21       SEG11
    
    Gpio_SetAnalogMode(GpioPortA, GpioPin3);  //SEG20       SEG10
    Gpio_SetAnalogMode(GpioPortA, GpioPin4);  //SEG19       SEG9
    Gpio_SetAnalogMode(GpioPortA, GpioPin5);  //SEG18       SEG8
    Gpio_SetAnalogMode(GpioPortA, GpioPin6);  //SEG17       SEG7

    Gpio_SetAnalogMode(GpioPortA, GpioPin8);  //SEG0       
    
    Gpio_SetAnalogMode(GpioPortA, GpioPin9);  //COM0
    Gpio_SetAnalogMode(GpioPortA, GpioPin10); //COM1
    Gpio_SetAnalogMode(GpioPortA, GpioPin11); //COM2
    Gpio_SetAnalogMode(GpioPortA, GpioPin12); //COM3   

    Gpio_SetAnalogMode(GpioPortC, GpioPin0);  //SEG27       SEG17
    Gpio_SetAnalogMode(GpioPortC, GpioPin1);  //SEG26       SEG16
    Gpio_SetAnalogMode(GpioPortC, GpioPin2);  //SEG25       SEG15
    Gpio_SetAnalogMode(GpioPortC, GpioPin3);  //SEG24       SEG14
    Gpio_SetAnalogMode(GpioPortC, GpioPin6);  //SEG4
    Gpio_SetAnalogMode(GpioPortC, GpioPin7);  //SEG3
    Gpio_SetAnalogMode(GpioPortC, GpioPin8);  //SEG2
    Gpio_SetAnalogMode(GpioPortC, GpioPin9);  //SEG1
    
    Gpio_SetAnalogMode(GpioPortB, GpioPin15); //SEG5
    Gpio_SetAnalogMode(GpioPortB, GpioPin14); //SEG6
}

/***********************************************************************************
 * @brief  lcd初始化
 * @param  供电选择   PW33  PW50
***********************************************************************************/
void lcd_init(uint8_t pw)
{
    Sysctrl_SetPeripheralGate(SysctrlPeripheralLcd,TRUE);   ///< 开启LCD时钟
    Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE);  ///< 开启GPIO时钟
    lcd_reg_init(pw);                 //LCD端口配置 
    Lcd_ClearDisp();                //清屏 
}
/***********************************************************************************
 * @brief  操作结果显示
 * @param  res=0 success    res=1 fail
***********************************************************************************/
void lcd_dis_result(uint8_t res)
{   
	uint32_t  ram[16]      = {0};
    //--------------------------------------------------------显示成功    
    if(res==0)//SUCC
    {
        ram[5] |= dis_table_1[0xf+1] | dis_table_2[0xf+2]; 
        ram[6] |= dis_table_1[0xc]   | dis_table_2[0xc];           
    }    
    if(res==1)//FAIL
    {
        ram[5] |= dis_table_1[0xf] | dis_table_2[0xa]; 
        ram[6] |= dis_table_1[0x1] | dis_table_2[0xf+3];           
    }
    if(res==2)//good
    {
        ram[5] |= dis_table_1[0xf+4] | dis_table_2[0xf+5]; 
        ram[6] |= dis_table_1[0xf+5] | dis_table_2[0xd];             
    }        
    //--------------------------------------------------------映射内存
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}

/***********************************************************************************
 * @brief  4位密码显示
 * @param  uint8_t  data_f  操作位闪烁
           uint8_t  data    显示的密码
***********************************************************************************/
void lcd_dis_num4(uint8_t  data_f,uint16_t data)
{   
	uint8_t   data_num[4]  = {0};
	uint32_t  ram[16]      = {0};
    uint8_t   addr_num[4]  = {0};
    //--------------------------------------------------------显示密码
    
    data_num[0] =  data         / 1000;
	data_num[1] = (data % 1000) / 100;
	data_num[2] = (data % 100)  / 10;
	data_num[3] = (data % 10);
	
    if(lcd_obj.flicker_flag==1)
    {
        ram[5] |= dis_table_1[data_num[0]] | dis_table_2[data_num[1]]; 
        ram[6] |= dis_table_1[data_num[2]] | dis_table_2[data_num[3]];                 
    } 
    else
    {
        switch (data_f)
        {
            case 0:ram[5] |= dis_table_2[data_num[1]]; 
                   ram[6] |= dis_table_1[data_num[2]] | dis_table_2[data_num[3]];break;
            case 1:ram[5] |= dis_table_1[data_num[0]]; 
                   ram[6] |= dis_table_1[data_num[2]] | dis_table_2[data_num[3]];break; 
            case 2:ram[5] |= dis_table_1[data_num[0]] | dis_table_2[data_num[1]]; 
                   ram[6] |= dis_table_2[data_num[3]];                           break;            
            case 3:ram[5] |= dis_table_1[data_num[0]] | dis_table_2[data_num[1]]; 
                   ram[6] |= dis_table_1[data_num[2]];                           break;    	
            default:break;	
        }
    }
    //--------------------------------------------------------内存映射
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}

/***********************************************************************************
* @brief  2位倒计时显示
***********************************************************************************/
void lcd_dis_num2(uint16_t addr,uint8_t data)
{   
	uint8_t   data_num[2]  = {0};
	uint32_t  ram[16]      = {0};
    uint8_t   addr_num[4]  = {0};
    //--------------------------------------------------------显示倒计时
	data_num[0] =  data / 10;
	data_num[1] =  data % 10;	    
    ram[6] |= dis_table_1[data_num[0]] | dis_table_2[data_num[1]]; 
    //--------------------------------------------------------显示左上角地址
    ram[4] |=LCD_ADDR;	   
    //--------------------------------------------------------设备地址
    addr_num[0] =  addr / 100;
    addr_num[1] = (addr / 10) % 10;
    addr_num[2] =  addr % 10;
    ram[4] |= dis_table_3[addr_num[0]];//addr1与2映射地址位相同
    ram[1] |= dis_table_3[addr_num[1]];
    switch (addr_num[2])
    {
    	case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
    	case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
    	case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
    	case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_G;break;	
    	case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
    	case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
    	case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
    	case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
    	case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
    	case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
    	default:break;  		
    }
    //--------------------------------------------------------内存映射
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}
/***********************************************************************************
* @brief  4位无符号数据设置  位置 数据 是否显示左上角地址
***********************************************************************************/
void lcd_set_uint(uint8_t data_f,uint16_t data,uint8_t adr_flag)
{
	uint8_t   data_num[6]  = {0};
	uint32_t  ram[16]      = {0};
    //--------------------------------------------------------数据显示
    data_num[1] = (data % 10000) / 1000;
	data_num[2] = (data % 1000)  / 100;
	data_num[3] = (data % 100)   / 10;
	data_num[4] =  data % 10;	
    //--------------------------------------------------------选择显示位   
    if(lcd_obj.flicker_flag==1)
    {
        ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
        ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];        
    } 
    else
    {
        switch (data_f)
        {
            case 0:ram[5] |= dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break;
            case 1:ram[5] |= dis_table_1[data_num[1]]; 
                   ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break; 
            case 2:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_2[data_num[4]];                           break;            
            case 3:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_1[data_num[3]];                           break;    	
            default:break;	
        }
    }
    if(adr_flag==PARA)
    {
        ram[4] |=LCD_ADDR;
  
    }
    
    //--------------------------------------------------------选择显示总位数
//    switch (data_cnt)
//    {
//        case 1:ram[5] &= ~(dis_table_1[data_num[1]] | dis_table_2[data_num[2]]);
//               ram[6] &= ~(dis_table_1[data_num[3]]);break; 
//        case 2:ram[5] &= ~(dis_table_1[data_num[1]] | dis_table_2[data_num[2]]);break; 
//        case 3:ram[5] &= ~dis_table_1[data_num[1]];break;                                      	
//        default:break;	
//    } 
    
    //--------------------------------------------------------内存映射
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}

/***********************************************************************************
* @brief  设置精度
* @param  dot1  '1'  0
                '2'  0.0
                '3'  0.00
***********************************************************************************/
void lcd_set_dot(char dot1)
{

	uint32_t  ram[16]      = {0};
    uint8_t dot = dot1 - '0';
 
    //--------------------------------------------------------显示0   
    switch (dot)
    {
        case 1:ram[6] |= dis_table_2[0];break;
               
        case 2:ram[6] |= dis_table_1[0] | dis_table_2[0];break; 
               
        case 3:ram[5] |= dis_table_2[0]; 
               ram[6] |= dis_table_1[0] | dis_table_2[0];break;                            break;               	
        default:break;	
    }
    //--------------------------------------------------------显示小数点
    switch (dot)
    {
    	case 1: ;break;	
    	case 2: ram[6] |=LCD_DP2;break;	  
    	case 3: ram[6] |=LCD_DP1;break;	          
    	default:break;  		
    }
    //--------------------------------------------------------内存映射
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}
/***********************************************************************************
* @brief  设置闪烁显示
* @param  uint8_t  data_f  操作位闪烁
***********************************************************************************/
void lcd_set_data(  uint8_t    data_cnt,\
                    uint8_t    data_f,\
                    uint32_t   data,\
                    uint8_t    dot1,\
                    uint8_t    sta,\
                    uint8_t    unit,\
                    uint8_t    par)
{
	uint8_t   data_num[6]  = {0};
	uint32_t  ram[16]      = {0};
    //--------------------------------------------------------精度装换
//    uint8_t dot = (uint8_t)(log10(dot1));
    uint8_t dot;
    switch (dot1)
    {
    	case 10: dot = 1;  break;	
    	case 100:dot = 2;  break;
    	default: dot = 0;  break;		
    }
    //--------------------------------------------------------数据显示    
    if(data>LCD_MAX_DATA) data = LCD_MAX_DATA;
    
	data_num[0] =  data          / 10000;
	data_num[1] = (data % 10000) / 1000;
	data_num[2] = (data % 1000)  / 100;
	data_num[3] = (data % 100)   / 10;
	data_num[4] =  data % 10;	
    //--------------------------------------------------------选择闪烁显示位   
    if(data_num[0]>0) 
        ram[4] |=LCD_DAT4; 
    if(lcd_obj.flicker_flag==1)
    {
        ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
        ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];        
    } 
    else
    {
        switch (data_f)
        {
            case 0:ram[5] |= dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break;
            case 1:ram[5] |= dis_table_1[data_num[1]]; 
                   ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break; 
            case 2:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_2[data_num[4]];                           break;            
            case 3:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                   ram[6] |= dis_table_1[data_num[3]];                           break;    	
            default:break;	
        }
    }
    //--------------------------------------------------------选择显示总位数
//    switch (data_cnt)
//    {
//        case 1:ram[5] &= ~(dis_table_1[data_num[1]] | dis_table_2[data_num[2]]);
//               ram[6] &= ~(dis_table_1[data_num[3]]);break; 
//        case 2:ram[5] &= ~(dis_table_1[data_num[1]] | dis_table_2[data_num[2]]);break; 
//        case 3:ram[5] &= ~dis_table_1[data_num[1]];break;                                      	
//        default:break;	
//    } 
    //--------------------------------------------------------设备运行状态
    switch (sta)
    {
    	case 0: ram[5] |=LCD_RUN ;break;	
    	case 1: ram[5] |=LCD_L_RP;break;	
    	case 2: ram[0] |=LCD_FAULT;break;
    	case 3: ram[0] |=LCD_H_RP;break;  
    	case 4: ram[0] |=LCD_TEST;break;          
    	default:break;  		
    }
    //--------------------------------------------------------传感器单位
    switch (unit)
    {   
      // 1     2     3      4     5
      //"%LEL","PPM","%VOL","%RH","'C"
    	case 1: ram[0] |=LCD_LEL;break;	
    	case 2: ram[0] |=LCD_PPM;break;	
    	case 3: ram[0] |=LCD_VOL;break;
    	case 4: ram[0] |=LCD_RH;break;  
    	case 5: ram[0] |=LCD_TEMP;break;          
    	default:break;  		
    }    
    //--------------------------------------------------------小数点 精度
    switch (dot)
    {
    	case 0: ;break;	
    	case 1: ram[6] |=LCD_DP2;break;	  
    	case 2: ram[6] |=LCD_DP1;break;	          
    	default:break;  		
    }
     //--------------------------------------------------------设置参数
    switch (par)
    {
    	case 0: ;break;	
    	case 1: ram[0] |=LCD_KUA;break;	  
    	case 2: ram[0] |=LCD_ZERO;break;	 
    	case 3: ram[0] |=LCD_CAL;break;	  
    	case 4: ram[0] |=LCD_RANGE;break;	 
    	case 5: ram[0]  =ram[0]|LCD_KUA|LCD_CAL;break;	         
    	default:break;  		
    }   
    //--------------------------------------------------------写入寄存器RAM
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
	
}
/***********************************************************************************
* @brief  主界面显示 
          addr_flag 左上角  “地址”是否显示
          addr_flag1 具体地址是否显示
***********************************************************************************/
void lcd_dis_main(  uint32_t  data,\
                    uint8_t   dot1,\
                    uint8_t   sta,\
                    uint8_t   unit,\
                    uint8_t   par,\
                    uint8_t   addr_flag,
                    uint8_t   addr_flag1,
                    uint16_t  addr)
{
	uint8_t   data_num[6]  = {0};
    uint8_t   addr_num[4]  = {0};
	uint32_t  ram[7]      = {0};
    //--------------------------------------------------------精度装换,小数点只管显示不参与运算
//    uint8_t dot = (uint8_t)(log10(dot1));//无math加速
    uint8_t dot;
    switch (dot1)
    {
    	case 10: dot = 1;  break;	
    	case 100:dot = 2;  break;
    	default: dot = 0;  break;		
    }
    //--------------------------------------------------------数据显示 
    if(data>LCD_MAX_DATA) data = LCD_MAX_DATA;
    
	data_num[0] =  data          / 10000;
	data_num[1] = (data % 10000) / 1000;
	data_num[2] = (data % 1000)  / 100;
	data_num[3] = (data % 100)   / 10;
	data_num[4] =  data % 10;	
    //--------------------------------------------------------选择显示位   
    if(data_num[0]>0) 
        ram[4] |=LCD_DAT4; 
    if(data_num[0]==0 && data_num[1]==0 && data_num[2]==0 && data_num[3]==0)
    {
        if(dot==2)
        {
            ram[5] |= dis_table_2[data_num[2]]; 
            ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];
        }
        else if(dot==1)
        {
            ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];
        }
        else
        {
            ram[6] |= dis_table_2[data_num[4]];
        }           
    }         
    else if(data_num[0]==0 && data_num[1]==0 && data_num[2]==0)
    { 
        if(dot>1)
        {
            ram[5] |= dis_table_2[data_num[2]]; 
            ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];
        }
        else
        {
            ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];
        }
    }
    else if(data_num[0]==0&&data_num[1]==0)
    {
        ram[5] |= dis_table_2[data_num[2]]; 
        ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];         
    }
    else
    {
        ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
        ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];  
    }
    //--------------------------------------------------------设备运行状态
    switch (sta)
    {
    	case 0: ram[5] |=LCD_RUN ;break;	
    	case 1: ram[5] |=LCD_L_RP;break;	
    	case 2: ram[0] |=LCD_H_RP;break;
    	case 3: ram[0] |=LCD_FAULT;break;  
    	case 4: ram[0] |=LCD_TEST;break;          
    	default:break;  		
    }
    //--------------------------------------------------------传感器单位
    switch (unit)
    {
      // 1     2     3      4     5
      //"%LEL","PPM","%VOL","%RH","'C"
    	case 1: ram[0] |=LCD_LEL;break;	
    	case 2: ram[0] |=LCD_PPM;break;	
    	case 3: ram[0] |=LCD_VOL;break;
    	case 4: ram[0] |=LCD_RH;break;  
    	case 5: ram[0] |=LCD_TEMP;break;             
    	default:break;  		
    }    
    //--------------------------------------------------------小数点 精度
    switch (dot)
    {
    	case 0: ;break;	
    	case 1: ram[6] |=LCD_DP2;break;	  
    	case 2: ram[6] |=LCD_DP1;break;	          
    	default:break;  		
    }
     //--------------------------------------------------------设置参数
    switch (par)
    {
    	case 0: ;break;	
    	case 1: ram[0] |=LCD_KUA;break;	  
    	case 2: ram[0] |=LCD_ZERO;break;	 
    	case 3: ram[0] |=LCD_CAL;break;	  
    	case 4: ram[0] |=LCD_RANGE;break;
    	case 5: ram[0]  =ram[0]|LCD_KUA|LCD_CAL;break;	        
    	default:break;  		
    }   
    //--------------------------------------------------------显示左上角地址
    if(addr_flag==PARA)
    {
        ram[4] |=LCD_ADDR;
    }
    if(addr_flag1==PARA)
    {
    //--------------------------------------------------------设备地址
        addr_num[0] =  addr / 100;
        addr_num[1] = (addr / 10) % 10;
        addr_num[2] =  addr % 10;
        ram[4] |= dis_table_3[addr_num[0]];//addr1与2映射地址位相同
        ram[1] |= dis_table_3[addr_num[1]];
        switch (addr_num[2])
        {
            case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
            case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
            case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
            case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_G;break;	
            case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
            case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
            default:break;  		
        }
     }
    //--------------------------------------------------------写入寄存器RAM
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}



/***********************************************************************************
* @brief  更改主机地址显示
***********************************************************************************/
void lcd_dis_host( uint8_t data_f,uint32_t  data,uint16_t  addr)
{
	uint8_t   data_num[6]  = {0};
    uint8_t   addr_num[4]  = {0};
	uint32_t  ram[7]      = {0};
    //--------------------------------------------------------数据处理
    if(data>LCD_MAX_DATA) data = LCD_MAX_DATA;
    
	data_num[0] =  data          / 10000;
	data_num[1] = (data % 10000) / 1000;
	data_num[2] = (data % 1000)  / 100;
	data_num[3] = (data % 100)   / 10;
	data_num[4] =  data % 10;	
    
    addr_num[2] =  addr % 10;
    //--------------------------------------------------------选择显示位  
    if(data_f<4)
    {
        if(lcd_obj.flicker_flag==1)
        {
            ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
            ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];        
        } 
        else
        {
            switch (data_f)
            {
                case 0:ram[5] |= dis_table_2[data_num[2]]; 
                       ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break;
                case 1:ram[5] |= dis_table_1[data_num[1]]; 
                       ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];break; 
                case 2:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                       ram[6] |= dis_table_2[data_num[4]];                           break;            
                case 3:ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
                       ram[6] |= dis_table_1[data_num[3]];                           break;    	
                default:break;	
            }
        }
        switch (addr_num[2])
        {
            case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
            case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
            case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
            case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_G;break;	
            case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
            case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
            default:break;  		
        }
        
    }
    //--------------------------------------------------------显示主机校验位  
    if(data_f==4)
    {
        ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
        ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];     
    
        if(lcd_obj.flicker_flag==1)//移动检验位闪烁
        {   
            switch (addr_num[2])
            {
                case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
                case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
                case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
                case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_G;break;	
                case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                        ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
                case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
                case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
                case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
                case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
                case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                        ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
                default:break;  		
            }
        }
    }
    //--------------------------------------------------------写入寄存器RAM
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
}

/***********************************************************************************
* @brief  显示当前版本
***********************************************************************************/
void lcd_dis_ver(uint32_t data,uint16_t  addr)
{
	uint8_t   data_num[6]  = {0};
    uint8_t   addr_num[4]  = {0};
	uint32_t  ram[7]      = {0};
    //--------------------------------------------------------数据处理
    if(data>LCD_MAX_DATA) data = LCD_MAX_DATA;
    
	data_num[0] =  data          / 10000;
	data_num[1] = (data % 10000) / 1000;
	data_num[2] = (data % 1000)  / 100;
	data_num[3] = (data % 100)   / 10;
	data_num[4] =  data % 10;	
    
    addr_num[2] =  addr % 10;
    //--------------------------------------------------------选择显示位  

    ram[5] |= dis_table_1[data_num[1]] | dis_table_2[data_num[2]]; 
    ram[6] |= dis_table_1[data_num[3]] | dis_table_2[data_num[4]];        

    switch (addr_num[2])
    {
        case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
        case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
        case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
        case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_G;break;	
        case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
        case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
        case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
        case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
        case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
        case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
        default:break;  		
    }
        
    //--------------------------------------------------------写入寄存器RAM
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }
    //--------------------------------------------------------开机显示版本延时
    delay1ms(1000);
}
/***********************************************************************************
* @brief  ON/OFF 显示 lcd_dis_switch(1);//on
***********************************************************************************/
void  lcd_dis_switch(uint8_t res)
{
    uint32_t  ram[7]      = {0};
    switch (res)
    {
        case 0:
            ram[5] |= dis_table_2[0x0f+5]; 
            ram[6] |= dis_table_1[0x0f] | dis_table_2[0x0f];  
            break;
        case 1:
            ram[6] |= dis_table_1[0x0f+5] | dis_table_2[0x0f+6];  
            break;
        default:break;
            
    }
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }   

}
/***********************************************************************************
* @brief  错误码显示
***********************************************************************************/
void lcd_dis_err(uint8_t err,uint16_t  addr)
{
	uint8_t   data_num[6]  = {0};
    uint8_t   addr_num[4]  = {0};
    uint32_t  ram[16]      = {0};
//    ram[5] |= dis_table_1[] | dis_table_2[]; 
    ram[6] |= dis_table_1[0x0e] | dis_table_2[err];  
    //--------------------------------------------------------写入寄存器RAM
    ram[0] |=LCD_FAULT;
    ram[4] |=LCD_ADDR;	
           
    //--------------------------------------------------------设备地址
        addr_num[0] =  addr / 100;
        addr_num[1] = (addr / 10) % 10;
        addr_num[2] =  addr % 10;
        ram[4] |= dis_table_3[addr_num[0]];//addr1与2映射地址位相同
        ram[1] |= dis_table_3[addr_num[1]];
        switch (addr_num[2])
        {
            case 0: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F;break;	
            case 1: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;break;
            case 2: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_G;break;	
            case 3: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_G;break;	
            case 4: ram[0] |=LCD_ADDR3_B|LCD_ADDR3_C;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 5: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 6: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 7: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C;break;	
            case 8: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_E|LCD_ADDR3_F|LCD_ADDR3_G;break;	
            case 9: ram[0] |=LCD_ADDR3_A|LCD_ADDR3_B|LCD_ADDR3_C|LCD_ADDR3_D;
                    ram[1] |=LCD_ADDR3_F|LCD_ADDR3_G;break;	      
            default:break;  		
        }
         
    for(uint8_t i=0;i<7;i++)
    {
        Lcd_WriteRam(i,ram[i]); 
    }    
}
/***********************************************************************************
* @brief  密码位闪烁
***********************************************************************************/
void lcd_password_flicker_timer(void)
{   
    lcd_obj.flicker_cnt++;
    if(lcd_obj.flicker_cnt<50)  lcd_obj.flicker_flag=0;        
    if(lcd_obj.flicker_cnt>50)  lcd_obj.flicker_flag=1;    
    if(lcd_obj.flicker_cnt>100) lcd_obj.flicker_cnt=0;       
}



